﻿#include "GameWorld.h"
#include "shader/ssShaderManager.h"
#include "console/ssConsole.h"
#include "node/ssNodeFactory.h"
#include "resmgr/ssResManager.h"


GameWorld::GameWorld()
	:m_sceneContent(m_scene)
{
}

GameWorld::~GameWorld(void)
{
}

void GameWorld::Init()
{
	SS_CONSOLE->Print("init game world...\n");

	SS_OPENGL->SetCullMode(SS_CULL_NULL);

	StarSeeker::ssShaderManager::instance()->CreateDefaultShader();
	SS_RES_MANAGR->CreateDefaultMesh();

	m_sceneContent.InitCamera();
	m_sceneContent.InitNode();
}

void GameWorld::OnMouseMove(i32 x, i32 y)
{
	m_sceneContent.OnMouseMove(x, y);
}

void GameWorld::OnMouseWheel(i32 w)
{
	m_sceneContent.OnMouseWheel(w);
}

void GameWorld::OnLeftUp(i32 x, i32 y)
{
	m_sceneContent.OnLeftUp(x,y);
}

void GameWorld::OnKeyDown(i32 k)
{
	m_sceneContent.OnKeyDown(k);
}

void GameWorld::OnKeyUp(i32 k)
{
}

void GameWorld::Render()
{
	m_scene.RenderScene();

	/*static f32 v[3 * 3] = { 0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, };
	static u32 m_handle = 0;
	static StarSeeker::ssShader* ptestShader = 0;
	static int m_glslID = -1;
	if (m_handle==0)
	{
	ptestShader = StarSeeker::ssShaderManager::instance()->Find("test");
	glGenBuffers(1, &m_handle);
	glBindBuffer(GL_ARRAY_BUFFER, m_handle);
	glBufferData(GL_ARRAY_BUFFER, sizeof(v), v, SS_VBO_STATIC);
	ptestShader->Use();
	m_glslID = ptestShader->GetAttribLocation("inPosition");
	if (m_glslID >= 0) //传递数据到显存
	{
	glEnableVertexAttribArray(m_glslID);
	glVertexAttribPointer(m_glslID, 3, GL_FLOAT, GL_FALSE, 0, 0);
	}
	}
	//glVertexPointer(3, GL_FLOAT, 0, 0);
	glDrawArrays(SS_PRIMITIVE_TRIANGLE, 0, 3);*/
}
